/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sims.gui.salesperson;

import java.util.ArrayList;
import java.util.Calendar;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import sims.entity.Order;
import sims.entity.OrderDetail;
import sims.entity.Product;
import sims.manager_SalesPerson.Function;

/**
 *
 * @author vanthanh
 */
public class OrderRerurned extends javax.swing.JPanel {

    /**
     * Creates new form OrderRerurned
     */
    DefaultTableModel modelview = new DefaultTableModel() {
        @Override
        public boolean isCellEditable(int i, int i1) {
            return false;
        }
    };
    DefaultTableModel modelReturn = new DefaultTableModel() {
        @Override
        public boolean isCellEditable(int i, int i1) {
            return false;
        }
    };

    public OrderRerurned() {
        initComponents();
    }
    String userName;
    String orderId;
    ArrayList<OrderDetail> arrOrderDetail = new ArrayList<OrderDetail>();

    public OrderRerurned(String orderId, String userName) {
        this.userName = userName;
        this.orderId = orderId;
        initComponents();
        Function fun = new Function();
        Order order = new Order();
        String[] column = {"STT", "ItemID", "Item Name", "Unit", "Price", "Amount", "Cost"};
        modelview.setColumnIdentifiers(column);
        modelReturn.setColumnIdentifiers(column);
        jTable_OrderReturn.setModel(modelReturn);
        /* cua order view */

        order = fun.getOrderbyId(orderId);
        arrOrderDetail = fun.getOrderDetailByOrderId(orderId);
        lbDatetime.setText(order.getDatetime().toString());
        String username = fun.getUserName(order.getUserId());
        lbUserName.setText(username);
        lbTotal.setText(String.valueOf(order.getTotal()));

        /* cua order return */

        // int userId = fun.getUserId("thanhtv");
        Calendar cal = Calendar.getInstance();
        lbUserName1.setText("thanhtv");
        lbDay1.setText(String.valueOf(cal.get(Calendar.DATE)));
        lbMonth1.setText(String.valueOf(cal.get(Calendar.MONTH) + 1));
        lbYear1.setText(String.valueOf(cal.get(Calendar.YEAR)));
        int stt = 0;
        for (OrderDetail od : arrOrderDetail) {
            stt++;
            Product pro = new Product();
            pro = fun.getProductById(od.getItemID());
            Object[] row = {stt, pro.getId(), pro.getProductName(), pro.getUnit(), od.getPriceSell(), od.getAmount(), (od.getPriceSell() * od.getAmount())};
            modelview.addRow(row);
        }
        jTable_OrderSell.setModel(modelview);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnOrderReturn = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable_OrderSell = new javax.swing.JTable();
        lbDatetime = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        lbTotal = new javax.swing.JLabel();
        lbUserName = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable_OrderReturn = new javax.swing.JTable();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        lbUserName1 = new javax.swing.JLabel();
        lbDay1 = new javax.swing.JLabel();
        lbMonth1 = new javax.swing.JLabel();
        lbYear1 = new javax.swing.JLabel();
        bnSubmit = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        txtAmount = new javax.swing.JTextField();
        bn_Ok = new javax.swing.JButton();
        bn_del = new javax.swing.JButton();
        txtItemName = new javax.swing.JTextField();
        lbTotal1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();

        setLayout(new java.awt.BorderLayout());

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel1.setText(" Sell Order ");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel2.setText("Datetime :");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel3.setText("User Name:");

        jTable_OrderSell.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(jTable_OrderSell);

        lbDatetime.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel8.setText("Total:");

        lbTotal.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        lbUserName.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(29, 29, 29)
                .addComponent(lbTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(28, 28, 28))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addGap(32, 32, 32)
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(lbDatetime, javax.swing.GroupLayout.DEFAULT_SIZE, 114, Short.MAX_VALUE)
                                    .addComponent(lbUserName, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addGap(149, 149, 149)
                                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 121, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2)
                    .addComponent(lbDatetime, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3)
                    .addComponent(lbUserName, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(14, 14, 14)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 263, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel8)
                    .addComponent(lbTotal, javax.swing.GroupLayout.DEFAULT_SIZE, 19, Short.MAX_VALUE))
                .addContainerGap(75, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        jLabel13.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel13.setText("-->");

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel4.setText("  Return Order");

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel5.setText("Datetime :");

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel9.setText("User Name :");

        jTable_OrderReturn.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane2.setViewportView(jTable_OrderReturn);

        jLabel10.setText("-");

        jLabel11.setText("-");

        jLabel12.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel12.setText("Total:");

        lbUserName1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        lbDay1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        lbMonth1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        lbYear1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        bnSubmit.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        bnSubmit.setText("Submit");
        bnSubmit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bnSubmitActionPerformed(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel6.setText("ItemName:");

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel7.setText("Amount:");

        bn_Ok.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        bn_Ok.setText("OK");
        bn_Ok.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bn_OkActionPerformed(evt);
            }
        });

        bn_del.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        bn_del.setText("Delete");
        bn_del.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bn_delActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(150, 150, 150))
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 464, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtItemName, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(2, 2, 2)
                        .addComponent(txtAmount, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(bn_Ok)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(bn_del))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGap(32, 32, 32)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE)
                                    .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lbUserName1, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(jPanel4Layout.createSequentialGroup()
                                        .addComponent(lbDay1, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(jPanel4Layout.createSequentialGroup()
                                                .addGap(14, 14, 14)
                                                .addComponent(lbMonth1, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(31, 31, 31)
                                                .addComponent(lbYear1, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addGroup(jPanel4Layout.createSequentialGroup()
                                                .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 12, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(35, 35, 35)
                                                .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGap(135, 135, 135)
                                .addComponent(bnSubmit)))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(jLabel10)
                            .addComponent(jLabel11))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel9))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lbYear1, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lbMonth1, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lbDay1, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lbUserName1, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(txtItemName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(txtAmount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(bn_Ok)
                    .addComponent(bn_del))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 257, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel12)
                .addGap(18, 18, 18)
                .addComponent(bnSubmit)
                .addGap(22, 22, 22))
        );

        lbTotal1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jButton1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jButton1.setText("Cancel");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap(263, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(lbTotal1, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(41, 41, 41))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addGap(154, 154, 154))))
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(lbTotal1, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(16, 16, 16)
                .addComponent(jButton1)
                .addGap(28, 28, 28))
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, 473, Short.MAX_VALUE)
                    .addContainerGap()))
        );

        javax.swing.GroupLayout pnOrderReturnLayout = new javax.swing.GroupLayout(pnOrderReturn);
        pnOrderReturn.setLayout(pnOrderReturnLayout);
        pnOrderReturnLayout.setHorizontalGroup(
            pnOrderReturnLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnOrderReturnLayout.createSequentialGroup()
                .addGap(13, 13, 13)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(5, 5, 5)
                .addComponent(jLabel13)
                .addGap(5, 5, 5)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        pnOrderReturnLayout.setVerticalGroup(
            pnOrderReturnLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnOrderReturnLayout.createSequentialGroup()
                .addGroup(pnOrderReturnLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnOrderReturnLayout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(pnOrderReturnLayout.createSequentialGroup()
                        .addGap(237, 237, 237)
                        .addComponent(jLabel13)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnOrderReturnLayout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 0, Short.MAX_VALUE)
                .addContainerGap())
        );

        add(pnOrderReturn, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents
    int stt = 0;
    private void bnSubmitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnSubmitActionPerformed
        Function fun = new Function();

        ArrayList<String> arrInsertOrder = new ArrayList<String>();
        ArrayList<String> arrInsertOrder_Item = new ArrayList<String>();
        String day = lbDay1.getText();
        String month = lbMonth1.getText();
        String year = lbYear1.getText();
        //String userId = lbUserName1.getText();
        int userId = fun.getUserId("thanhtv");
        float total = 0;
        for (int i = 0; i < jTable_OrderReturn.getRowCount(); i++) {
            total += Float.parseFloat(jTable_OrderReturn.getValueAt(i, 6).toString());

            int itemId = Integer.parseInt(jTable_OrderReturn.getValueAt(i, 1).toString());
            for (OrderDetail od : arrOrderDetail) {
                if (itemId == od.getItemID()) {
                    arrOrderDetail.remove(od);
                    break;
                }
            }
        }
        Calendar cal = Calendar.getInstance();
        int hour = cal.get(Calendar.HOUR);
        int minute = cal.get(Calendar.MINUTE);
        int second = cal.get(Calendar.SECOND);
        String datetime = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second + "";

        if (jTable_OrderReturn.getRowCount() > 0) {
            String insertOrder = "insert into orders values ('" + datetime + "','" + userId + "','Returned','successed'," + total + ")";
            arrInsertOrder.add(insertOrder);
            fun.runBath(arrInsertOrder);
            int OrderId = fun.getOrderId(userId);
            for (int i = 0; i < jTable_OrderReturn.getRowCount(); i++) {
                String itemId = jTable_OrderReturn.getValueAt(i, 1).toString();
                int Amount = Integer.parseInt(jTable_OrderReturn.getValueAt(i, 5).toString());
                float price = Float.parseFloat(jTable_OrderReturn.getValueAt(i, 4).toString());
                String insertOrderItem = "insert into order_item values(" + OrderId + ",'" + itemId + "'," + Amount + "," + price + ")";
                arrInsertOrder_Item.add(insertOrderItem);
            }
            fun.runBath(arrInsertOrder_Item);
            ArrayList<String> arrupdate = new ArrayList<String>();
            String update = "update orders set status ='returned'where orderId =" + orderId + "";
            arrupdate.add(update);
            fun.runBath(arrupdate);
            JOptionPane.showMessageDialog(this, "Submit successfull");
            this.removeAll();
            ListSellOrder lst = new ListSellOrder(userName);
            this.add(lst);
            this.validate();
            //xoa het cac row trong bang
//            int rows = modelReturn.getRowCount();
//            for (int i = rows - 1; i >= 0; i--) {
//                modelReturn.removeRow(i);
//            }
//            lbTotal1.setText("");
//            
        } else {
            JOptionPane.showMessageDialog(this, "don't have Item returned!!!");

        }

    }//GEN-LAST:event_bnSubmitActionPerformed

    private void bn_delActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bn_delActionPerformed
        if (jTable_OrderReturn.getSelectedRow() == -1) {
            JOptionPane.showMessageDialog(this, "select item need delete");
        } else {
            int x = jTable_OrderReturn.getSelectedRow();
            modelReturn.removeRow(x);
            float total = 0;
            for (int i = 0; i < jTable_OrderReturn.getRowCount(); i++) {
                total += Float.parseFloat(jTable_OrderReturn.getValueAt(i, 6).toString());
            }
            lbTotal1.setText(String.valueOf(total));
        }
        this.repaint();
    }//GEN-LAST:event_bn_delActionPerformed

    private void bn_OkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bn_OkActionPerformed
        if ("".equals(txtItemName.getText()) || "".equals(txtAmount.getText())) {
            JOptionPane.showMessageDialog(this, "Item ID and Amount must not null!!!");
        } else if (!txtAmount.getText().matches("[1-9][0-9]*")) {
            JOptionPane.showMessageDialog(this, "Amount must is number!!!");
        } else {
            boolean checkIdtrung = true;
            for (int i = 0; i < jTable_OrderReturn.getRowCount(); i++) {
                if (txtItemName.getText().equals(jTable_OrderReturn.getValueAt(i, 2).toString())) {
                    checkIdtrung = false;
                    JOptionPane.showMessageDialog(this, "ItemId existed");
                    break;
                }
            }
            if (checkIdtrung) {
                Function fun = new Function();
                boolean flag = true;
                int amount = Integer.parseInt(txtAmount.getText());
                for (OrderDetail od : arrOrderDetail) {
                    if (txtItemName.getText().equals(od.getItemName())) {
                        flag = false;
                        if (amount > 0 && amount <= od.getAmount()) {
                            stt++;
                            Product pro = new Product();
                            pro = fun.getProductById(od.getItemID());
                            Object[] row = {stt, od.getItemID(), pro.getProductName(), pro.getUnit(), od.getPriceSell(), od.getAmount(), (od.getPriceSell() * od.getAmount())};
                            modelReturn.addRow(row);
                            jTable_OrderReturn.setModel(modelReturn);
                            txtAmount.setText("");
                            txtItemName.setText("");
                            float total = 0;
                            for (int i = 0; i < jTable_OrderReturn.getRowCount(); i++) {
                                total += Float.parseFloat(jTable_OrderReturn.getValueAt(i, 6).toString());
                            }
                            lbTotal1.setText(String.valueOf(total));
                            break;
                        }
                        if (amount < 0) {
                            JOptionPane.showMessageDialog(this, "error: amount < 0");
                        }
                        if (amount > od.getAmount()) {
                            JOptionPane.showMessageDialog(this, "error: amount > amount purchased");
                        }
                    }
                }
                if (flag) {
                    JOptionPane.showMessageDialog(this, "ItemID don't have in sell order ");
                }
            }
        }
    }//GEN-LAST:event_bn_OkActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        if (jTable_OrderReturn.getRowCount() > 0) {
            int Submit = JOptionPane.showConfirmDialog(this, "are you sure want cancel ?", null, JOptionPane.YES_NO_OPTION);
            if (Submit == JOptionPane.OK_OPTION) {
                this.removeAll();
                ListSellOrder lst = new ListSellOrder(userName);
                this.add(lst);
                this.validate();
            }
        }

    }//GEN-LAST:event_jButton1ActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bnSubmit;
    private javax.swing.JButton bn_Ok;
    private javax.swing.JButton bn_del;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable_OrderReturn;
    private javax.swing.JTable jTable_OrderSell;
    private javax.swing.JLabel lbDatetime;
    private javax.swing.JLabel lbDay1;
    private javax.swing.JLabel lbMonth1;
    private javax.swing.JLabel lbTotal;
    private javax.swing.JLabel lbTotal1;
    private javax.swing.JLabel lbUserName;
    private javax.swing.JLabel lbUserName1;
    private javax.swing.JLabel lbYear1;
    private javax.swing.JPanel pnOrderReturn;
    private javax.swing.JTextField txtAmount;
    private javax.swing.JTextField txtItemName;
    // End of variables declaration//GEN-END:variables
}
